<?
	
	//require_once('../fun/accounts.php');
	require_once('../fun/sources.php');
	$results = array();
	if(isset($_POST['id']))
	{
		$row = $_POST;
		$results = ValidateSource($row);
		if($results === true)
			$results = CreateSource($row);
		if($results === true)
		{
			if(isset($_REQUEST['ajax'])){
				$rs = GetSource($row['id']);
			}else{
				header("Location: index.php");
			}
			die();
		}
	}else{
		if(isset($_REQUEST['id']))
			$row = GetSource($_REQUEST['id']);
		else
			$row = BlankSource();
	}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>&psi; Psychology Database &psi;</title>
<? include ("../inc/required-links.php") ?>
</head>

<body>
<div id="wrapper">
	<div id="l_l"></div> 
    <div id="left">
		<?php include ('../nav/sources.php') ?>
    </div>
    <div id="main">
		<?php include ('../inc/header.php') ?>
        <div id="t_bg"></div>
        <div id="content">
			<div class="otstup">
            	<div id="main_left">
					<div class="corners">
                    	<div class="text">
                <form class="createForm formPost" method="post" action="edit.php" style="width:420px;">
                    <div class="modal-header" style="text-align:center;"><h1>Reference a Source</h1></div>
                    <div>
                        <label for="Title">Title:</label>
                        <div>
                            <input type="text" name="Title" id="Title" value="<?=$row['Title']?>"
                            class="required <?=isset($results['Title']) ? 'error' : '' ?>" style="width:400px;" />
                            <span class="error"><?=isset($results['Title']) ? $results['Title'] : '' ?></span>
                        </div>
                    </div>
                    <div>
                        <label for="Author">Author:</label>
                        <div>
                            <input type="text" name="Author" id="Author" value="<?=$row['Author']?>"
                            class="required <?=isset($results['Author']) ? 'error' : '' ?>" style="width:400px;"/>
                            <span class="error"><?=isset($results['Author']) ? $results['Author'] : '' ?></span>
                        </div>
                    </div>
                    <div>
                        <label for="PublishYear">PublishYear:</label>
                        <div>
                            <input type="text" name="PublishYear" id="PublishYear" value="<?=$row['PublishYear']?>"
                            class="required <?=isset($results['PublishYear']) ? 'error' : '' ?>" style="width:400px;" />
                            <span class="error"><?=isset($results['PublishYear']) ? $results['PublishYear'] : '' ?></span>
                        </div>
                    </div>
                    <div>
                        <label for="Cite">Cite:</label>
                        <div>
                            <input type="text" name="Cite" id="Cite" value="<?=$row['Cite']?>"
                            class="required <?=isset($results['Cite']) ? 'error' : '' ?>" style="width:400px;" />
                            <span class="error"><?=isset($results['Cite']) ? $results['Cite'] : '' ?></span>
                        </div>
                    </div>
                    <div class="control-group modal-footer">
                       <input type="hidden" name="id" id="id" value="<?=$row['id']?>" />
                       <input class="btn btn-mini" style="margin-top:10px;" type="submit" value="Update" />
                    </div>
                </form>
                <br /><a href="http://cs.newpaltz.edu<?=$_GET['returnUrl']?>">Cancel</a>
                        </div>
                    </div>
                </div>
                <div id="right">
					<?php include ('../inc/cat_box1.php') ?>
					<?php include ('../inc/cat_box3.php') ?>
					<?php include ('../inc/cat_box4.php') ?>
					<?php include ('../inc/sn_links.php') ?>
                </div>
        		<div class="clear"></div>
        	</div>
        </div>
        <div class="clear"></div>  
        <div id="foot">
        	<?php include ('../inc/footer.php') ?>
		</div>
		<?php include ('../inc/copywright.php') ?>
        </div>
<div class="clear"></div> 
</div>
</body>
</html>
<? include ("../inc/required-js.php") ?>
